package com.liang.drug.service.impl;/*
 *@Author: ljy
 *@Date:2021/10/31 23:22
 *
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liang.drug.entity.Owinfo;
import com.liang.drug.mapper.OwinfoMapper;
import com.liang.drug.service.IOwinfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 药品出入库 service 实现类
 */
@Service
public class OwinfoServiceImpl extends ServiceImpl<OwinfoMapper, Owinfo> implements IOwinfoService {
    //@Autowired
    @Resource
    private OwinfoMapper owinfoMapper;

    /**
     * @param pageNum  第几页
     * @param pageSize 每页的数量
     * @param param    查询参数 药品出入库名称
     * @return
     */
    @Override
    public IPage<Owinfo> selectOwinfoPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Owinfo> queryWrapper = new QueryWrapper<>();
        //工具类为mybatisPlus的工具类
        if (StringUtils.isNotEmpty(param)) {
            queryWrapper.like("dname", param);
        }
        Page<Owinfo> page = new Page<>(pageNum, pageSize);
        return owinfoMapper.selectPage(page, queryWrapper);
    }

    /**
     * 插入
     * @param owinfo
     * @return
     */
    @Override
    public int addOwinfo(Owinfo owinfo) {
        return owinfoMapper.insert(owinfo);
    }

    /**
     * 修改
     * @param owinfo
     * @return
     */
    @Override
    public int editOwinfo(Owinfo owinfo) {
        return owinfoMapper.updateById(owinfo);
    }

    /**
     * 根据主键id查询一个药品出入库对象
     * @param id
     * @return
     */
    @Override
    public Owinfo queryOwinfoById(Integer id) {
        return owinfoMapper.selectById(id);
    }

    /**
     * 根据主键id删除一个药品出入库对象
     * @param id
     * @return
     */
    @Override
    public int delOwinfoById(Integer id) {
        return owinfoMapper.deleteById(id);
    }


}
